﻿Imports DTO
Imports DAO
Imports BUS
Public Class ThongTinNhanVien
    Function checkState()
        Dim state = 0
        If rdMa.Checked = True Then
            state = 1
        ElseIf rdMa.Checked = True Then
            state = 2
        Else
            state = 0
        End If
        Return state
    End Function

    Sub Load_info()
        Dim dt As New DataTable()
        Dim nv As New NhanVienBUS()
        dt = nv.GetTable()
        dtgvNhanVien.DataSource = dt
    End Sub

    Private Sub btnTim_Click(sender As System.Object, e As System.EventArgs) Handles btnTim.Click
        Dim dt As New DataTable()
        Dim nv As New NhanVienBUS()
        If checkState() = 1 Then
            dt = nv.TimTheoMa(txtMa.Text)
        ElseIf checkState() = 2 Then
            dt = nv.TimTheoTen(txtHoTen.Text)
        Else
            dt = nv.GetTable()
        End If
    End Sub

    Private Sub ThongTinNhanVien_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim ds As List(Of TaiKhoanDTO) = New List(Of TaiKhoanDTO)
        Dim tk As New TaiKhoanBUS()
        ds = tk.GetList()
        cbMaTK.DataSource = ds
        cbMaTK.DisplayMember = "MaTK"
        Load_info()
    End Sub

    Private Sub btnThem_Click(sender As System.Object, e As System.EventArgs) Handles btnThem.Click
        Dim nv As New NhanVienDTO()
        nv.MaNV = txtMa.Text
        nv.TenNV = txtHoTen.Text
        nv.MaTK = cbMaTK.Text
        nv.DiaChi = txtDiaChi.Text
        nv.DienThoai = txtSoDienThoai.Text
        nv.Email = txtmail.Text
        nv.LuongCB = txtLuongCB.Text
        nv.HeSoLuong = txtHeSoLuong.Text
        nv.NgayVaoLam = DTNgayLam.Text

        Dim them As New NhanVienBUS()
        them.Them(nv)
        Load_info()
    End Sub

    Private Sub btnXoa_Click(sender As System.Object, e As System.EventArgs) Handles btnXoa.Click
        Dim ma = txtMa.Text
        Dim nv As New NhanVienBUS()
        nv.Xoa(ma)
        Load_info()
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim nv As New NhanVienDTO()
        nv.MaNV = txtMa.Text
        nv.TenNV = txtHoTen.Text
        nv.MaTK = cbMaTK.Text
        nv.DiaChi = txtDiaChi.Text
        nv.DienThoai = txtSoDienThoai.Text
        nv.Email = txtmail.Text
        nv.LuongCB = Single.Parse(txtLuongCB.Text)
        nv.HeSoLuong = Single.Parse(txtHeSoLuong.Text)
        nv.NgayVaoLam = DTNgayLam.Text
        Dim them As New NhanVienBUS()
        them.CapNhat(nv)
        Load_info()
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Close()
    End Sub

    Private Sub dtgvNhanVien_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgvNhanVien.CellClick
        Dim i = dtgvNhanVien.CurrentRow.Index
        txtMa.Text = dtgvNhanVien.Item(0, i).Value.ToString
        txtHoTen.Text = dtgvNhanVien.Item(1, i).Value.ToString
        cbMaTK.Text = dtgvNhanVien.Item(2, i).Value.ToString
        txtDiaChi.Text = dtgvNhanVien.Item(3, i).Value.ToString
        txtmail.Text = dtgvNhanVien.Item(4, i).Value.ToString
        txtSoDienThoai.Text = dtgvNhanVien.Item(5, i).Value.ToString
        DTNgayLam.Text = dtgvNhanVien.Item(6, i).Value.ToString
        txtLuongCB.Text = dtgvNhanVien.Item(7, i).Value.ToString
        txtHeSoLuong.Text = dtgvNhanVien.Item(8, i).Value.ToString
    End Sub
End Class